<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use DB;
class OrderController extends Controller
{
    public function getIndex(){
        // var_dump(session('home_userid'));
        //关联查询用户所有订单信息
        $res2=DB::table("tbl_order")
        ->join("tbl_home_user","tbl_order.uid","=","tbl_home_user.id")
        ->join("tbl_goods","tbl_order.gid","=","tbl_goods.id")
        ->where("tbl_order.uid","=",session("home_userid"))
        ->get();
         // dd($res2);
        //查询出对应的订单id
        $res2_id=DB::table("tbl_order")
        ->join("tbl_home_user","tbl_order.uid","=","tbl_home_user.id")
        ->join("tbl_goods","tbl_order.gid","=","tbl_goods.id")
        ->where("tbl_order.uid","=",session("home_userid"))
        ->lists('tbl_order.id');
        //通过遍历 将订单id 覆盖到订单信息的id
        $arr=[];
        foreach($res2 as $k => $v){
            $arr[$k] = $v;
            $arr[$k]['id'] =  $res2_id[$k];
        }
       
        
         //关联查询用户所有待发货订单信息
        $res3=DB::table("tbl_order")
        ->join("tbl_home_user","tbl_order.uid","=","tbl_home_user.id")
        ->join("tbl_goods","tbl_order.gid","=","tbl_goods.id")
        ->where("tbl_order.uid","=",session("home_userid"))
        ->where("tbl_order.orderstatus","=",'待发货')
        ->get();
        $res3_id=DB::table("tbl_order")
        ->join("tbl_home_user","tbl_order.uid","=","tbl_home_user.id")
        ->where("tbl_order.uid","=",session("home_userid"))
        ->where("tbl_order.orderstatus","=",'待发货')
        ->lists('tbl_order.id');
        // var_dump($res3);
        $arr3=[];
        foreach($res3 as $k => $v){
            $arr3[$k] = $v;
            $arr3[$k]['id'] =  $res3_id[$k];
        }
        // dd($res3);

         //关联查询用户所有待收货订单信息
        $res4=DB::table("tbl_order")
        ->join("tbl_home_user","tbl_order.uid","=","tbl_home_user.id")
        ->join("tbl_goods","tbl_order.gid","=","tbl_goods.id")
        ->where("tbl_order.uid","=",session("home_userid"))
        ->where("tbl_order.orderstatus","=",'待收货') 
        ->get();
        $res4_id=DB::table("tbl_order")
        ->join("tbl_home_user","tbl_order.uid","=","tbl_home_user.id")
        ->where("tbl_order.uid","=",session("home_userid"))
        ->where("tbl_order.orderstatus","=",'待收货') 
        ->lists('tbl_order.id');
        $arr4=[];
        foreach($res4 as $k => $v){
            $arr4[$k] = $v;
            $arr4[$k]['id'] =  $res4_id[$k];
        }
        // var_dump($res4_id);
        // dd($arr4);

         //关联查询用户所有待付款订单信息
        $res5=DB::table("tbl_order")
        ->join("tbl_home_user","tbl_order.uid","=","tbl_home_user.id")
        ->join("tbl_goods","tbl_order.gid","=","tbl_goods.id")
        ->where("tbl_order.uid","=",session("home_userid"))
        ->where("tbl_order.orderstatus","=",'待付款')
        ->get();

        $res5_id=DB::table("tbl_order")
        ->join("tbl_home_user","tbl_order.uid","=","tbl_home_user.id")
        ->join("tbl_goods","tbl_order.gid","=","tbl_goods.id")
        ->where("tbl_order.uid","=",session("home_userid"))
        ->where("tbl_order.orderstatus","=",'待付款')
        ->lists('tbl_order.id');

        $arr5=[];
        foreach($res5 as $k => $v){
            $arr5[$k] = $v;
            $arr5[$k]['id'] =  $res5_id[$k];
        }
        // dd($arr5);

         //关联查询用户所有待评价订单信息
        $res6=DB::table("tbl_order")
        ->join("tbl_home_user","tbl_order.uid","=","tbl_home_user.id")
        ->join("tbl_goods","tbl_order.gid","=","tbl_goods.id")
        ->where("tbl_order.uid","=",session("home_userid"))
        ->where("tbl_order.orderstatus","=",'待评价')
        ->get();
        $res6_id=DB::table("tbl_order")
        ->join("tbl_home_user","tbl_order.uid","=","tbl_home_user.id")
        ->join("tbl_goods","tbl_order.gid","=","tbl_goods.id")
        ->where("tbl_order.uid","=",session("home_userid"))
        ->where("tbl_order.orderstatus","=",'待评价')
        ->lists('tbl_order.id');

        $arr6=[];
        foreach($res6 as $k => $v){
            $arr6[$k] = $v;
            $arr6[$k]['id'] =  $res6_id[$k];
        }

    return view('home/order/order',['list'=>$arr,'list3'=>$arr3,'list4'=>$arr4,'list5'=>$arr5,'list6'=>$arr6,]);
    }

    public function getDelete(){
        $id=$_GET['id'];
        $res = DB::table('tbl_order') -> where('id',$id) ->delete();
        if($res){
            echo "删除成功";
        }else{
            echo '删除失败';
        }

    }
}
    
